/**
 *	会员分组
 *
 *	@auth zongjl
 *	@date 2018-08-17
 */
layui.use(['func', 'form'], function () {

    //【声明变量】
    var func = layui.func
            , form = layui.form
            , $ = layui.$;



    //【TABLE列数组】
    var cols = [
        {type: 'checkbox', fixed: 'left'}
        , {field: 'id', width: 80, title: 'ID', align: 'center', sort: true, fixed: 'left'}
        , {field: 'title', width: 300, title: '标题', align: 'left', templet: function (row) {
                var title = row.title;
                if (row.thumb) {
                    title = '<span class="layui-btn layui-btn-normal layui-btn-xs">图</span><a href="' + row.url + '" target="_blank">' + row.title+'</a>';
                }
                return title;
            }
        }
        , {field: 'hits', width: 80, title: '点击量', align: 'center'}
        , {field: 'cityName', width: 80, title: '城市', align: 'center'}
        , {field: 'userid', width: 80, title: '用户ID', align: 'center'}
        , {field: 'mobile', width: 120, title: '手机', align: 'center'}
        , {field: 'contact', width: 100, title: '发布人', align: 'center'}
        , {field: 'cfrom', width: 70, title: '来源', align: 'center', templet: function (d) {
                var str = "";
                if (d.cfrom == 1) {
                    str = '<span class="layui-btn layui-btn-xs layui-btn-xs">个人</span>';
                } else {
                    str = '<span class="layui-btn layui-btn-normal layui-btn-xs layui-btn-danger">中介</span>';
                }
                return str;
            }
        }
        , {field: 'supplyName', width: 70, title: '供给', align: 'center', sort: true, templet: function (row) {
                var cls = "";
                if (row.supply == 1) {
                    //模块
                    cls = "layui-btn-normal";
                } else if (row.supply == 2) {
                    //导航
                    cls = "layui-btn-danger";
                } else if (row.supply == 3) {
                    //菜单
                    cls = "layui-btn-warm";
                } else if (row.supply == 4) {
                    //节点
                    cls = "";
                }
                return '<span class="layui-btn ' + cls + ' layui-btn-xs">' + row.supplyName + '</span>';
            }}
        , {field: 'updatetime', width: 200, title: '更新时间', align: 'center', sort: true, templet: function (row) {
                if (row.updatetime != row.addtime) {
                    return '<font style="color:#ff0;">' + row.updatetime + '</font>';
                } else {
                    return row.updatetime;
                }
            }
        }
        , {field: 'addtime', width: 200, title: '发布时间', align: 'center', sort: true}
        , {field: 'status', width: 80, title: '状态', align: 'center', templet: "#statusTpl", fixed: 'right'}
        , {fixed: 'right', width: 150, title: '功能操作区', align: 'center', toolbar: '#toolBar'}
    ];
    //监听性别操作
    //【状态开关】
    form.on('switch(status)', function (obj) {
        //提示
        layer.tips('温馨提示：关闭后将不在前端显示', obj.othis)
        var status = this.checked ? '1' : '2';
        $.ajax({
            url: cUrl + "/setstatus",
            dataType: "json",
            type: "POST",
            data: {"id": this.value, "status": status},
            beforeSend: function () {
                layer.msg('处理中。。。', {
                    icon: 16
                    , shade: 0.01
                    , time: 0
                });
            },
            success: function (res) {
                if (res.success) {
                    //2秒后关闭
                    layer.msg(res.msg, {icon: 1, time: 1000}, function () {
                        layer.close(index);
                    });
                } else {
                    layer.msg(res.msg, {icon: 5});
                }
            }
        });

    });

    //【渲染TABLE】
    func.tableIns(cols, "tableList");

    //【设置弹框】
    func.setWin("会员分组", 450, 250);


});
